﻿using System;
using System.Collections.Generic;
using System.Data.Services.Client;
using System.Linq;
using System.Reflection;
using System.Text;

namespace Common.Unity.Extensions.Entity.Extensions
{
	public static class DataServiceQuery
	{
		public static DataServiceQuery<ObjectType> Load<ObjectType>( this DataServiceQuery<ObjectType> query )
		{
			return ResolveDataQuery( query, new List<ObjectType>() );
		}

		static DataServiceQuery<ObjectType> ResolveDataQuery<ObjectType>( DataServiceQuery<ObjectType> query, ICollection<ObjectType> current )
		{
			List<ObjectType> list = new List<ObjectType>( query );
			if ( current.Count < list.Count  )
			{
				return ResolveDataQuery( query, list );
			}
			return query;
		}

	}
}
